package com.com.effectivejava.comparator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Logger;

/**
 * Created by User on 18/08/2014.
 */
public class TestComparator {
    static Logger logger = Logger.getLogger(TestComparator.class.getName());

    static {
        logger.setParent(Logger.getLogger(TestComparator.class.getPackage().getName()));
    }

    public static void main(String[] args) {
        final Employee e1 = new Employee(2);
        final Employee e2 = new Employee(4);

        List<Employee> list = new ArrayList<Employee>(){{
          add(e1);
          add(e2);
        }};

        Collections.sort(list, new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                // This gives the latest employee first. or descending order.
                return o2.id - o1.id;

                // This gives the oldest employee first. or ascending order.
                // return o1.id - o2.id;
            }
        });

        for(Employee e : list){
            logger.info(e.id + "");
        }
    }
}

class Employee{
    int id;
    public Employee(int id){
        this.id = id;
    }
}
